package com.feel.common.mybatis;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @program: feel-generator
 * @description: 自动填充时间
 * @author: Jianfeng LIAN
 * @nickname: 我自然
 * @email : 2580040689@qq.com
 * @github :https://github.com/woizran
 * @date: 2021-06-05 00:28
 **/
@Configuration
@Slf4j
public class MyDetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
//        log.info("come to insert fill .........");
        //setFieldValByName(String fieldName, Object fieldVal, MetaObject metaObject)
        this.setFieldValByName("createTime", new Date(), metaObject);
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
//        log.info("come to update fill .......");
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }
}
